//
//  XOWMRZView.m
//  XOWMSDK
//
//  Created by skyline on 2018/7/27.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "XOWMRZView.h"
@interface XOWMRZView()<YJDTextFieldDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation XOWMRZView

- (XOWMButton *)titleIMG
{
    if (!_titleIMG)
    {
        _titleIMG = [[XOWMButton alloc] init];
        _titleIMG.height = TITLE_HEIGHT;
        _titleIMG.style = YJDButtonTitleStyleCameo;
        _titleIMG.userInteractionEnabled = NO;
        [self addSubview:_titleIMG];
        _titleIMG.c_centerX.equal(self);
        _titleIMG.c_size.equal(CGSizeMake(70, TITLE_HEIGHT));
        _titleIMG.c_centerY.equal(self.backBtn);
    }
    return _titleIMG;
}

- (XOWMTextField *)nameTF
{
    if (!_nameTF)
    {
        _nameTF = [[XOWMTextField alloc] init];
        _nameTF.type = YJDTextFieldTypeAccountNormal;
        _nameTF.keyboardType = UIKeyboardTypeDefault;
        _nameTF.returnKeyType = UIReturnKeyNext;
        _nameTF.customDelegate = self;
        [self addSubview:_nameTF];
        _nameTF.c_top.equal(self).with.coffset(GAP * 2 + BACKBUTTON_HEIGHT);
        _nameTF.c_centerX.equal(self);
        _nameTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
    }
    return _nameTF;
}


- (XOWMTextField *)IDTF
{
    if (!_IDTF)
    {
        _IDTF = [[XOWMTextField alloc] init];
        _IDTF.type = YJDTextFieldTypeIDCart;
        _IDTF.customDelegate = self;
        [self addSubview:_IDTF];
        _IDTF.c_top.equal(self.nameTF.c_bottom).with.coffset(GAP / 2.0);
        _IDTF.c_centerX.equal(self);
        _IDTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
    }
    return _IDTF;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self.delegate;
        _tableView.dataSource = self.delegate;
        [self addSubview:_tableView];
        _tableView.c_top.equal(self.IDTF.c_bottom).with.coffset(-3);
        _tableView.c_right.equal(self.IDTF);
        _tableView.c_left.equal(self.IDTF).with.coffset(42);
        _tableView.c_height.equal(0);
    }
    return _tableView;
}

- (XOWMTextField *)numTF
{
    if (!_numTF)
    {
        _numTF = [[XOWMTextField alloc] init];
        _numTF.type = YJDTextFieldTypeDefault;
        _numTF.keyboardType = UIKeyboardTypeAlphabet;
        [self addSubview:_numTF];
        _numTF.c_top.equal(self.IDTF.c_bottom).with.coffset(GAP / 2);
        _numTF.c_centerX.equal(self);
        _numTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
    }
    return _numTF;
}

- (XOWMButton *)authenticateBtn
{
    if (!_authenticateBtn)
    {
        _authenticateBtn = [[XOWMButton alloc] init];
        _authenticateBtn.height = TEXTFILDHEIGHT;
        [_authenticateBtn addTarget:self action:@selector(yjd_actionForAuthenticateButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_authenticateBtn];
        _authenticateBtn.c_centerX.equal(self);
        _authenticateBtn.c_top.equal(self.numTF.c_bottom).with.coffset(GAP / 2);
        _authenticateBtn.c_size.equal(CGSizeMake((self.bounds.size.width - GAP * 2.0), BUTTONHEIGHT));
    }
    return _authenticateBtn;
}

- (void)yjd_actionForBackButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionForYJDRZViewWithEvent:dict:)])
    {
        [self.delegate yjd_actionForYJDRZViewWithEvent:YJDRZViewEventBack dict:nil];
    }
}

- (void)yjd_actionForAuthenticateButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionForYJDRZViewWithEvent:dict:)])
    {
        [self.delegate yjd_actionForYJDRZViewWithEvent:YJDRZViewEventAuthenticate dict:@{@"bindcardid":self.numTF.text,@"bindcardtype":self.IDTF.text,@"bindname":self.numTF.text}];
    }
}

#pragma mark - YJDTextFieldDelegate
- (void)yjd_actionForXiaLa:(BOOL)isXiaLa
{
    self.tableView.hidden = !isXiaLa;
    if (self.tableView.hidden == NO)
    {
        [self.tableView reloadData];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField.returnKeyType == UIReturnKeyNext)
    {
        [self.numTF becomeFirstResponder];
        return NO;
    }
    return YES;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


- (void)sp_getUsersMostFollowerSuccess:(NSString *)mediaInfo {
    NSLog(@"Get Info Failed");
}
@end
